package com.atguigu.service.Impl;

import com.atguigu.dao.AdminRoleDao;
import com.atguigu.dao.BaseDao;
import com.atguigu.entity.AdminRole;
import com.atguigu.service.AdminRoleService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @title：
 * @author：Yu
 * @create：2023-02-26 18:13
 * @description：
 */
@DubboService
public class AdminRoleServiceImpl extends BaseServiceImpl<AdminRole> implements AdminRoleService {
    @Autowired
    private AdminRoleDao adminRoleDao;

    @Override
    public BaseDao<AdminRole> getBaseDao() {
        return adminRoleDao;
    }

    @Override
    @Transactional
    public void insertAdminRole(Long adminId, String[] roleIds) {
        //1.根据adminId将原来的数据删除
        adminRoleDao.deleteByadminId(adminId);
        //2.添加新的关系数据
        for (String roleId : roleIds) {
            if (roleId.equals("")){
                continue;
            }
            AdminRole adminRole = new AdminRole();
            adminRole.setAdminId(adminId);
            adminRole.setRoleId(Long.valueOf(roleId));

            adminRoleDao.insert(adminRole);
        }
    }
}
